cmake_minimum_required(VERSION 3.5)
include(GNUInstallDirs)

project(dal)
include(version.cmake)

MESSAGE(STATUS "SDK_ROOT: $ENV{SDKTARGETSYSROOT}")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -std=c++17 -g")
# Set the default value of DAL_ENABLE_DMABUFHEAP to OFF
option(DAL_ENABLE_DMABUFHEAP "Enable DMA BUF HEAP" OFF)

foreach (_pathName ${CMAKE_PREFIX_PATH})
    include_directories(${_pathName}/include)
    link_directories(${_pathName}/lib)
    message(STATUS "add include_directories(${_pathName}/include)")
    message(STATUS "add link_directories(${_pathName}/lib)")
endforeach()

include_directories(${PROJECT_SOURCE_DIR}/dal/include)
include_directories(${PROJECT_SOURCE_DIR}/dal_utils/include)
include_directories(${PROJECT_SOURCE_DIR}/dal_fastdds/include)
include_directories(${PROJECT_SOURCE_DIR}/dal_cyclonedds/include)
if(${BUILD_RTIDDS})
include_directories(${PROJECT_SOURCE_DIR}/dal_rticonnextdds/include)
endif()
# include_directories(${PROJECT_SOURCE_DIR}/dal_greenstonedds/include)
# include_directories(${PROJECT_SOURCE_DIR}/dal_greenstonedds/include/greenstoneDDS)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64" OR CMAKE_HOST_SYSTEM_PROCESSOR  MATCHES "aarch64")
    include_directories(${CMAKE_INCLUDE_PATH})
    link_directories(${CMAKE_LIBRARY_PATH})
endif()

# used for dal demo build
include_directories(${PROJECT_SOURCE_DIR}/dal_msg/include/dalidl/dalidl_runtime_c)
include_directories(${PROJECT_SOURCE_DIR}/dal_msg/include/dalidl/dalidl_runtime_cpp)

add_subdirectory(dal)
add_subdirectory(dal_utils)
add_subdirectory(dal_msg)
add_subdirectory(dal_msg_gen)
add_subdirectory(dal_fastdds)
add_subdirectory(dal_cyclonedds)
if(${BUILD_RTIDDS})
add_subdirectory(dal_rticonnextdds)
endif()
# add_subdirectory(dal_greenstonedds)
add_subdirectory(TestCases)

if (DAL_ENABLE_DMABUFHEAP)
add_subdirectory(dal_dmabufheap)
endif()

set ( PackageName "Dal" )
set ( PackageHeaderAnchor "dal/publisher.h" )
set ( PackageLibAnchor "dal" )

set(PackageLibryNames)
list ( APPEND PackageLibryNames dal)

install(TARGETS ${PackageLibryNames} EXPORT ${PackageName}Targets
        RUNTIME       DESTINATION ${CMAKE_INSTALL_BINDIR}
        LIBRARY       DESTINATION ${CMAKE_INSTALL_LIBDIR}
        ARCHIVE       DESTINATION ${CMAKE_INSTALL_DATADIR}
)

install(EXPORT ${PackageName}Targets
        FILE ${PackageName}Targets.cmake
        DESTINATION share/${PackageName}/cmake
        )


include ( CMakePackageConfigHelpers )
configure_package_config_file ( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PackageName}Config.cmake.in
	share/${PackageName}/cmake/${PackageName}Config.cmake
	INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/${PackageName}/cmake
)

write_basic_package_version_file(
  share/${PackageName}/cmake/${PackageName}ConfigVersion.cmake
  VERSION 0.0.3
  COMPATIBILITY AnyNewerVersion
)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/share/${PackageName}/cmake/${PackageName}Config.cmake"
	"${CMAKE_CURRENT_BINARY_DIR}/share/${PackageName}/cmake/${PackageName}ConfigVersion.cmake"
    DESTINATION ${CMAKE_INSTALL_DATADIR}/${PackageName}/cmake
)


